// fastclick
function fastClick() {
    if ('addEventListener' in document) {
        document.addEventListener('DOMContentLoaded', function() {
            FastClick.attach(document.body);
        }, false);
    }
}

const eventBus = new Vue();


// 加减器组件
let counter = {
    template: `<div class="popBox-counter">
  <span class="reduce" @click="reduce()">-</span>
  <input class="input" type="text" v-model="val"  pattern="[0-9]*">
  <span class="add" @click="add()">+</span>
  </div>`,
    props: ["buynum"],
    data() {
        return {
            val: this.buynum
        }
    },
    methods: {
        reduce: function() {
            if (this.val > 0) {
                this.val--;

            } else {
                this.val = 0;
            }

        },
        add: function() {
            this.val++;
        },

    },
    watch: {
        // 保存购物车数量
        val: function() {
            sessionStorage.setItem("cartCount", this.val)
        }
    }

}


/**
 * 时间转换 标准时间
 * @param  {[string]} dateTime [时间戳]
 * @param  {[type]} type     [需要转化的类型]
 * 0:yy-mm-dd
 * 1:yy-mm-dd h:min
 * 2:yy-mm
 * @return {[type]}          [转化后的时间]
 */


function formatNormal(dateTime, type) {
    var unixTimestamp = new Date(dateTime);
    var y = unixTimestamp.getFullYear();
    var m = unixTimestamp.getMonth() + 1;
    var d = unixTimestamp.getDate();
    var h = unixTimestamp.getHours();
    var min = unixTimestamp.getMinutes();
    if (m < 10) {
        m = "0" + m;
    }
    if (d < 10) {
        d = "0" + d;
    }
    if (h < 10) {
        h = "0" + h;
    }
    if (min < 10) {
        min = "0" + min;
    }

    var time0 = y + "-" + m + "-" + d;
    var time1 = y + "-" + m + "-" + d + " " + h + ":" + min;
    var time2 = y + "-" + m;


    if (type == 0) {
        return time0;
    }
    if (type == 1) {
        return time1;
    }
    if (type == 2) {
        return time2;
    }
}